From Peter Roosen
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 22 Oct 2002 18:48:08 +0000 (18:48 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 22 Oct 2002 18:48:08 +0000 (18:48 +0000)
Add -t, -w, -r command lines
Activate/fix code in magproto to parse tracks.
From me:
csv, dna, holux, mxf, ozi, psp, tpg, misc language conformance cleanups.

gpsbabel/csv.c
gpsbabel/defs.h
gpsbabel/dna.c
gpsbabel/holux.c
gpsbabel/magellan.h
gpsbabel/magproto.c
gpsbabel/main.c
gpsbabel/mxf.c
gpsbabel/ozi.c
gpsbabel/psp.c
gpsbabel/tpg.c

index 8f2df9dc9e1726de688e6c393e57efdebcac003a..4e90207e31ce6d694ce37f785693110c8f575143 100644 (file)
@@ -85,7 +85,7 @@ data_read(void)
 
        do {
                linecount++;
-               memset(&buff, '\0', sizeof(buff));
+               memset(buff, '\0', sizeof(buff));
                fgets(buff, sizeof(buff), file_in);
                  
                if (strlen(buff)) {
index 88271b8afde9ed5dde6bf505ad3280f98d935b14..b33ac3ff75d45890b96f8feae5ab0e52c85d07e4 100644 (file)
  * data in this file.
  */
 
-typedef struct {
-       int synthesize_shortnames;
-       int debug_level;
-} global_options;
-
-extern global_options global_opts;
 
 /*
  * A coordinate in space.
@@ -64,6 +58,27 @@ typedef struct {
        altitude altitude;
 } position;
 
+
+/*
+ * Define globally on which kind of data gpsbabel is working.
+ * Important for "file types" that are essentially a communication
+ * protocol for a receiver, like the Magellan serial data.
+ */
+typedef enum {
+       trkdata = 0 ,
+       wptdata,
+       rtedata
+} gpsdata_type;
+
+typedef struct {
+       int synthesize_shortnames;
+       int debug_level;
+       gpsdata_type objective;
+} global_options;
+
+extern global_options global_opts;
+
+
 /*
  * Extended data if waypoint happens to represent a geocache.  This is 
  * totally voluntary data...
index d4116e9830888fb7dabdad3659797713721be22c..10b0c699ef5b96db7c3386aecb18addb199704b2 100644 (file)
@@ -72,7 +72,7 @@ data_read(void)
 
        do {
                linecount++;
-               memset(&buff, '\0', sizeof(buff));
+               memset(buff, '\0', sizeof(buff));
                fgets(buff, sizeof(buff), file_in);
                  
                if (strlen(buff)) {
@@ -87,7 +87,7 @@ data_read(void)
 
                while (s) {
                        switch (i) {
-                       case 0: // WPT #, skip.
+                       case 0: /* WPT #, skip. */
                          break;
                        case 1:
                                wpt_tmp->position.latitude.degrees = atof(s);
index a233f9ba29e6e12fc1a990bee810c5fdad67aca2..04fa7c3a03c204e1459f73ce9ab17f12b07c264f 100644 (file)
@@ -85,8 +85,6 @@ static void data_read(void)
     int iWptNum;
     int iWptIndex;
     WPT *pWptHxTmp;
-    int iWptLen;
-    DWORD dwIndex;
        struct tm tm;
        struct tm *ptm;
 
@@ -101,7 +99,6 @@ static void data_read(void)
                fatal("GPSBABEL: Error reading data from .wpo file\n");
     }
 
-    iWptLen = sizeof(WPT);
     iWptNum = le_read16(&((WPTHDR *)HxWpt)->num);
 
     /* Get the waypoints */
@@ -110,7 +107,6 @@ static void data_read(void)
         wpt_tmp = xcalloc(sizeof(*wpt_tmp), 1);
     
        iWptIndex = le_read16(&((WPTHDR *)HxWpt)->idx[iCount]);
-        dwIndex= OFFS_WPT + (sizeof(WPT) * iWptIndex);
         pWptHxTmp =  (WPT *)&HxWpt[OFFS_WPT + (sizeof(WPT) * iWptIndex)];
         
         wpt_tmp->position.altitude.altitude_meters = 0;
@@ -196,15 +192,15 @@ static void holux_disp(const waypoint *wpt)
     /* set Waypoint */
     pWptHxTmp =  (WPT *)&HxWFile[OFFS_WPT + (sizeof(WPT) * sIndex)];
 
-    memset (&(pWptHxTmp->name),0x20,sizeof(pWptHxTmp->name));  
+    memset (pWptHxTmp->name,0x20,sizeof(pWptHxTmp->name));  
     if (wpt->shortname != NULL)
-        strncpy((char *)&(pWptHxTmp->name), mknshort(wpt->shortname,sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name));
+        strncpy(pWptHxTmp->name, mknshort(wpt->shortname,sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name));
     else
-        sprintf((char *)&(pWptHxTmp->name),"W%d",sIndex);
+        sprintf(pWptHxTmp->name,"W%d",sIndex);
 
-    memset (&(pWptHxTmp->comment),0x20,sizeof(pWptHxTmp->comment));  
+    memset (pWptHxTmp->comment,0x20,sizeof(pWptHxTmp->comment));  
     if (wpt->description != NULL)
-            strncpy((char *)&(pWptHxTmp->comment), mknshort(wpt->description,sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment));
+            strncpy(pWptHxTmp->comment, mknshort(wpt->description,sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment));
 
     /*set the time */
        if (wpt->creation_time) 
index 8f4d2c14cc278f83f7a57e8fc90998a6b4dffd2a..6d401f17570babc0e3bb18418ad52e35a4daef87 100644 (file)
@@ -45,3 +45,5 @@ typedef struct icon_mapping {
 
 const char * mag_find_descr_from_token(const char *token);
 const char * mag_find_token_from_descr(const char *icon);
+
+waypoint * mag_trkparse(char *trkmsg);
index 83272a2a2dbdc80863f814ac8940741791c2035e..3c88c3f4b373ceb27e32bc47e29c8c5019640b4b 100644 (file)
@@ -37,6 +37,8 @@ HANDLE comport;
 
 #define debug_serial  (global_opts.debug_level > 1)
 
+extern gpsdata_type objective;
+
 static char * termread(char *ibuf, int size);
 static void termwrite(char *obuf, int size);
 
@@ -344,9 +346,9 @@ mag_readmsg(void)
        isump = &ibuf[isz-1];
        isum  = strtoul(isump, NULL,16); 
        if (isum != mag_pchecksum(&ibuf[1], isz-3)) {
-if (debug_serial)
-               fprintf(stderr, "RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf);
-               /* Special case receive errors early on. */
+               if (debug_serial)
+                       fprintf(stderr, "RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf);
+                       /* Special case receive errors early on. */
                if (!got_version) {
                        fatal(MYNAME ": bad communication.  Check bit rate.\n");
                }
@@ -362,6 +364,10 @@ if (debug_serial)
                waypoint *wpt = mag_wptparse(ibuf);
                waypt_add(wpt);
        } 
+       if (strncmp(ibuf, "$PMGNTRK,", 7) == 0) {
+               waypoint *wpt = mag_trkparse(ibuf);
+               waypt_add(wpt);
+       } 
        if (IS_TKN("$PMGNVER,")) {
                mag_verparse(ibuf);
                return;
@@ -613,7 +619,8 @@ mag_deinit(void)
                fclose(magfile_in);
        magfile_in = NULL;
 }
-#if 0
+
+
 /*
  * Given an incoming track messages of the form:
  * $PMGNTRK,3605.259,N,08644.389,W,00151,M,201444.61,A,,020302*66
@@ -639,7 +646,7 @@ mag_trkparse(char *trkmsg)
 
        sscanf(trkmsg,"$PMGNTRK,%lf,%c,%lf,%c,%d,%c,%d.%d,A,,%d", 
                &latdeg,&latdir,
-               &lngdeg,&lngsecs,&lngdir,
+               &lngdeg,&lngdir,
                &alt,&altunits,&hms,&fracsecs,&dmy);
 
        tm.tm_sec = hms % 100;
@@ -667,7 +674,8 @@ mag_trkparse(char *trkmsg)
        return waypt;
        
 }
-#endif
+
+
 
 const char *
 mag_find_descr_from_token(const char *token)
@@ -773,15 +781,24 @@ mag_wptparse(char *trkmsg)
 }
 
 static void
-mag_readwpt(void)
+mag_read(void)
 {
        if (!is_file) {
-               mag_writemsg("PMGNCMD,WAYPOINT");
+               switch (global_opts.objective)
+               {
+                       case trkdata:
+                               mag_writemsg("PMGNCMD,TRACK,2");
+                               break;
+                       case wptdata:
+                               mag_writemsg("PMGNCMD,WAYPOINT");
+                               break;
+                       default:
+                               fatal(MYNAME ": Routes are not yet supported\n");
+               }
        }
 
-       while (!found_done) {
+       while (!found_done)
                mag_readmsg();
-       }
 }
 
 static
@@ -871,6 +888,6 @@ ff_vecs_t mag_vecs = {
        mag_wr_init,    
        mag_deinit,     
        mag_deinit,     
-       mag_readwpt,
+       mag_read,
        mag_write,
 };
index 29701dc2744b524bbe25d37c101a52a8af883bb7..e0730a34e3a99c3dacd23f55a6ea7191434177ca 100644 (file)
 
 global_options global_opts;
 
+gpsdata_type objective = wptdata; /* if no explicit data type is given, assume waypoints */
+
+
+
 void
 usage(const char *pname)
 {
-       printf("Usage: %s [-s] -i <INPUT_FILE_TYPE> -f <INPUT_FILE> -o <OUT FTYPE> -F <OUTPUT_FILE>\n", pname);
+       printf("Usage: %s [-s] [-t|-w|-r] -i <INPUT_FILE_TYPE> -f <INPUT_FILE> -o <OUT FTYPE> -F <OUTPUT_FILE>\n", pname);
        printf("Supported file types:\n");
        disp_vecs();
 }
@@ -94,6 +98,15 @@ main(int argc, char *argv[])
                        case 's':
                                global_opts.synthesize_shortnames = 1;
                                break;
+                       case 't':
+                               objective = trkdata;
+                               break;
+                       case 'w':
+                               objective = wptdata;
+                               break;
+                       case 'r':
+                               objective = rtedata;
+                               break;
                        case 'D':
                                global_opts.debug_level = atoi(optarg);
                                argn++;
index 412fa69a111d0171218742904fe590db448cd13c..e2e25e1483b3ee9de496fffa691ef86aa33092ce 100644 (file)
@@ -78,7 +78,7 @@ data_read(void)
 
     do {
         linecount++;
-       memset(&buff, '\0', sizeof(buff));
+       memset(buff, '\0', sizeof(buff));
        fgets(buff, sizeof(buff), file_in);
 
        if (strlen(buff)) {
index 0f6ec4612241b3677dd0198caf6db0bb2dd0686b..3ef4ac262c5cec0a4a2aa4a461018aae1742ac7e 100644 (file)
@@ -77,7 +77,7 @@ data_read(void)
 
     do {
         linecount++;
-       memset(&buff, '\0', sizeof(buff));
+       memset(buff, '\0', sizeof(buff));
        fgets(buff, sizeof(buff), file_in);
 
        if ((strlen(buff)) && (strstr(buff, ",") != NULL)) {
index 5e4773a8033a475d58d9e0741261a737eead07b9..c8a7527515298579fb5944139bffe5e3ccc1988b 100644 (file)
@@ -361,8 +361,8 @@ psp_waypt_pr(const waypoint *wpt)
         lon = (wpt->position.longitude.degrees * M_PI) / 180.0;
 
         /* 4 leading bytes */
-        memset(&tbuf, '\0', sizeof(tbuf));
-        fwrite(&tbuf, 1, 4, psp_file_out);
+        memset(tbuf, '\0', sizeof(tbuf));
+        fwrite(tbuf, 1, 4, psp_file_out);
 
         /* my test files seem to always have this byte as 0x03, */
         /* although nothing seems to really care.               */
@@ -381,16 +381,16 @@ psp_waypt_pr(const waypoint *wpt)
         c = 0x14; /* display pin name on! display notes on! */
         fwrite(&c, 1, 1, psp_file_out);
 
-        memset(&tbuf, '\0', sizeof(tbuf));
+        memset(tbuf, '\0', sizeof(tbuf));
 
         /* 3 unknown bytes */
-        fwrite(&tbuf, 1, 3, psp_file_out);
+        fwrite(tbuf, 1, 3, psp_file_out);
 
         /* 1 icon byte 0x00 = PIN */
-        fwrite(&tbuf, 1, 1, psp_file_out);
+        fwrite(tbuf, 1, 1, psp_file_out);
 
         /* 3 unknown bytes */
-        fwrite(&tbuf, 1, 3, psp_file_out); /* 3 junk */
+        fwrite(tbuf, 1, 3, psp_file_out); /* 3 junk */
 
         c = strlen(shortname);
         /* 1 string size */
@@ -448,7 +448,7 @@ psp_write(void)
         /* insert waypoint count into header */
        le_write16(&header_bytes[12], s);
 
-        fwrite(&header_bytes, 1,  32, psp_file_out);
+        fwrite(header_bytes, 1,  32, psp_file_out);
 
         waypt_disp_all(psp_waypt_pr);
 }
index 603961ad14b7a3590f14ab8848ea57aa23b76b78..d7dd62c11c030b22d3b494f2d40d8a10ed4d0b1b 100644 (file)
@@ -321,8 +321,8 @@ tpg_waypt_pr(const waypoint *wpt)
         fwrite(&elev, 1, 2, tpg_file_out);
 
         /* 4 unknown bytes */
-        memset(&tbuf, '\0', sizeof(tbuf));
-        fwrite(&unknown4, 1, 4, tpg_file_out);
+        memset(tbuf, '\0', sizeof(tbuf));
+        fwrite(unknown4, 1, 4, tpg_file_out);
 
         /* 1 bytes stringsize for description */
         c = strlen(description);
@@ -332,7 +332,7 @@ tpg_waypt_pr(const waypoint *wpt)
         fwrite(description, 1, c, tpg_file_out);
 
         /* and finally 2 unknown bytes */
-        fwrite(&unknown2, 1, 2, tpg_file_out);
+        fwrite(unknown2, 1, 2, tpg_file_out);
         
         free (shortname);
         free (description);
@@ -359,13 +359,13 @@ tpg_write(void)
             fatal(MYNAME ": attempt to output too many points (%d).  The max is %d.  Sorry.\n", s, MAXTPGOUTPUTPINS);
         }
 
-       le_write16(&uc, s);
+       le_write16(uc, s);
 
         /* write the waypoint count */
-        fwrite(&uc, 1,  2, tpg_file_out);
+        fwrite(uc, 1,  2, tpg_file_out);
 
         /* write the rest of the header */
-        fwrite(&header_bytes, 1, 19, tpg_file_out);
+        fwrite(header_bytes, 1, 19, tpg_file_out);
 
         waypt_disp_all(tpg_waypt_pr);
 }